import { _decorator, Component, Node } from 'cc';
import { GlobalTmpData } from '../../Init/Config/GlobalTmpData';
import EventManager from '../../Init/Managers/EventManager';
import { EventTypes } from '../../Init/Managers/EventTypes';
import { SDKSystem, PlatformType } from '../../Init/SystemSDK/SDKSystem';
import { StorageSystem } from '../../Init/SystemStorage/StorageSystem';
import { UIEnum } from '../../Init/SystemUI/UIEnum';
import { UISystem } from '../../Init/SystemUI/UISystem';
import { GlobalConfig } from '../../Init/Config/GlobalConfig';
import Tools from '../../Init/Tools/Tools';
const { ccclass, property } = _decorator;
// 首页自动弹出检测
@ccclass('AutoCheck')
export class AutoCheck extends Component {
    protected onLoad(): void {
        EventManager.on(EventTypes.SignUIEvents.SignSuccess, this.onSignSuccess, this);
    }
    onEnable() {
        this.autoShowUI();
    }


    update(dt: number): void {

    }

    autoShowUI() {
        // 只弹出一种
        let isPop = this.checkPrivacyUI();

        if (!isPop) {
            // isPop = this.checkSignUI();
        }

    }


    //#region ---隐私政策
    // 隐私政策
    checkPrivacyUI() {
        //自动弹出一次
        // if (SDKSystem._curPlatform == PlatformType.OPPOMiniGame ||
        //     SDKSystem._curPlatform == PlatformType.VIVOMiniGame ||
        //     SDKSystem._curPlatform == PlatformType.PCMiniGame) {
        //     if (StorageSystem.getData().userSetting.showPrivacy) {
        //         UISystem.showUI(UIEnum.PrivacyUI, { isLobby: false });
        //     }
        // }
        return false;
    }
    //#endregion

    //#region ---签到
    @property(Node)
    signBtn: Node = null;

    /**检测签到 */
    checkSignUI() {
        let data = StorageSystem.getData();
        let signData = data.userAssets.signData;

        let isPop = false;
        //判断当天是否签到
        let _isChecked = Tools.isSameDay(signData.lastTime);
        //判断当前是否已弹出过
        let isPoped = Tools.isSameDay(signData.prePopTime);

        if (!_isChecked && !isPoped) {
            isPop = true;
            signData.prePopTime = new Date().getTime();
            StorageSystem.saveData();
            UISystem.showUI(UIEnum.SignUI);
        }
        // 显示红点
        this.signBtn.getChildByName('tip').active = isPop;

        return isPop;
    }
    onSignSuccess() {
        // 隐藏红点
        this.signBtn.getChildByName('tip').active = false;
    }
    //#endregion



}

